//
//  SettingViewController.swift
//  1604_LimitFree
//
//  Created by 千锋 on 16/9/29.
//  Copyright © 2016年 Afei. All rights reserved.
//

import UIKit

class SettingViewController: LFNavViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //导航
        createMyNav()
        //按钮
        createBtns()
    }
    
    func createMyNav(){
        //返回按钮
        addBackButton()
        //标题
        addNavTitle("设置")

    }
    
    
    func createBtns(){
        let imageArray = ["account_setting","account_favorite","account_user","account_collect","account_download","account_comment","account_help","account_candou"]
        let titleArray = ["我的设置","我的关注","我的账号","我的收藏","我的下载","我的评论","我的帮助","蚕豆下载"]
        //
        let colNum = 3
        let btnW:CGFloat = 60
        let btnH:CGFloat = 60
        let titleH:CGFloat = 20
        let offsetX:CGFloat = 50
        let offsetY:CGFloat = 160 //第一行按钮的Y值
        let spaceX:CGFloat = (KScreenWidth - offsetX*2-btnW*CGFloat(colNum))/(CGFloat(colNum)-1)
        let spaceY:CGFloat = 80 //按钮之间的行间距
        for i in 0..<imageArray.count {
            
            let row = i/colNum
            let col = i%colNum
            
            let btnX = offsetX + (btnW+spaceX)*CGFloat(col)
            let btnY = offsetY + (btnH+titleH+spaceY)*CGFloat(row)
            
            //1.按钮
            let btn = UIButton.createBtn(CGRectMake(btnX, btnY, btnW, btnH), title: nil, bgImageName: imageArray[i], target: self, action: "clickBtn:")
            btn.tag = 200+i
            view.addSubview(btn)
            
            //2.文字
            let label = UILabel.createLabelFrame(CGRectMake(btnX, btnY+btnH, btnW, titleH), title: titleArray[i], textAlignment: .Center)
            label.font = UIFont.systemFontOfSize(12)
            view.addSubview(label)
            
        }
        
    }
    func clickBtn(btn:UIButton){
        let index = btn.tag - 200
        //print(index)
        
        if index == 3 {
            //收藏
            let collectCtrl = CollectViewController()
            hidesBottomBarWhenPushed = true
            navigationController?.pushViewController(collectCtrl, animated: true)
        }
        
        
    }

}
